from html import escape, unescape


def check_types(obj, types):
    if type(obj) in types: return True
    raise TypeError(f'The type accepted by the function is {types}, not the {type(obj)} you entered.')


def is_get(request): return request.method == 'GET'


def is_post(request): return request.method == 'POST'


def is_put(request): return request.method == 'PUT'


def is_delete(request): return request.method == 'DELETE'


def HTMLEntitiesToUnicode(text):
    """Converts HTML entities to unicode.  For example '&amp;' becomes '&'."""
    unescape(text)
    return text


def unicodeToHTMLEntities(text):
    """Converts unicode to HTML entities.  For example '&' becomes '&amp;'."""
    text = escape(text).encode('ascii', 'xmlcharrefreplace')
    return text
